<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>09-v-for中的key说明</title>
</head>
<body>
  <div id="app">
    <h1>vue的例子</h1>
    <p>{{msg}}</p>
    <ul>
      <li v-for="(item,index) in list" :key="item.id">{{item.name}}</li>
    </ul>
    <input type="button" value="添加值" @click="btnAdd">
  </div>
  <script src="../js/vue.js"></script>
  <script>
    Vue.config.productionTip = false; // 关闭生产提示
    const vm = new Vue({
      el: '#app',
      data: {
        msg: 'hello',
        list: [
          { id: 1, name: 'jack', age: 20 },
          { id: 2, name: 'tom', age: 21 },
          { id: 3, name: 'rose', age: 22 },
        ],
      },
      methods: {
        btnAdd() {
          this.list.unshift({ id: 4, name: 'jerry', age: 23 })
        }
      }
    })
  </script>
</body>
</html>